home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3006 / 3006.xpi / components / dhFlashgotDownloadProcessor.js < prev    next >
Text File  |  2010-01-15  |  6KB  |  178 lines

  1. /******************************************************************************
  2.  *            Copyright (c) 2006-2009 Michel Gutierrez. All Rights Reserved.
  3.  ******************************************************************************/
  4.  
  5. /**
  6.  * Constants.
  7.  */
  8.  
  9. const NS_FDLPROC_CID = Components.ID("{6d2d4306-a218-4be4-bdc4-61630dd7df7e}");
  10. const NS_FDLPROC_PROG_ID = "@downloadhelper.net/flashgot-download-processor;1";
  11. const DHNS = "http://downloadhelper.net/1.0#";
  12.  
  13. var Util=null;
  14.  
  15. /**
  16. * Object constructor
  17. */
  18. function FDLProc() {
  19.     try {
  20.         //dump("[FDLProc] constructor\n");
  21.         this.flashGot=null;
  22.         try {
  23.             this.flashGot=Components.classes["@maone.net/flashgot-service;1"].
  24.                 getService(Components.interfaces.nsISupports).wrappedJSObject;
  25.             this.core=Components.classes["@downloadhelper.net/core;1"].
  26.                 getService(Components.interfaces.dhICore);
  27.             this.core.registerProcessor(this);
  28.         } catch(e) {}
  29.  
  30.     } catch(e) {
  31.         dump("[FDLProc] !!! constructor: "+e+"\n");
  32.     }
  33. }
  34.  
  35. FDLProc.prototype = {
  36.     get name() { return "flashgot-download"; },
  37.     get provider() { return "DownloadHelper"; },
  38.     get title() { return Util.getText("processor.flashgot-download.title"); },
  39.     get description() { return Util.getText("processor.flashgot-download.description"); },
  40.     get enabled() { return true; },
  41. }
  42.  
  43. FDLProc.prototype.canHandle=function(desc) {
  44.     dump("[FDLProc] canHandle()\n");
  45.     return desc.has("media-url");
  46. }
  47.  
  48. FDLProc.prototype.requireDownload=function(desc) {
  49.     dump("[FDLProc] requireDownload()\n");
  50.     return false;
  51. }
  52.  
  53. FDLProc.prototype.preDownload=function(desc) {
  54.     dump("[FDLProc] preDownload()\n");
  55.     return false;
  56. }
  57.  
  58. FDLProc.prototype.handle=function(desc) {
  59.     dump("[FDLProc] handle()\n");
  60.     var mediaUrl=Util.getPropsString(desc,"media-url");
  61.     var link={
  62.             href: mediaUrl,
  63.             description: ""
  64.     }
  65.     var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  66.                                             .getService(Components.interfaces.nsIWindowMediator);
  67.     var window = windowMediator.getMostRecentWindow("navigator:browser");
  68.     window.gFlashGot.download([link],window.gFlashGotService.OP_ONE,null);
  69. }
  70.  
  71. FDLProc.prototype.QueryInterface = function(iid) {
  72.     //dump("[FDLProc] QueryInterface("+iid+")\n");
  73.     if(
  74.         iid.equals(Components.interfaces.dhIProcessor) ||
  75.         iid.equals(Components.interfaces.nsISupports)
  76.     ) {
  77.         return this;
  78.     }
  79.     throw Components.results.NS_ERROR_NO_INTERFACE;
  80. }
  81.  
  82. var vFDLProcModule = {
  83.     firstTime: true,
  84.     
  85.     /*
  86.      * RegisterSelf is called at registration time (component installation
  87.      * or the only-until-release startup autoregistration) and is responsible
  88.      * for notifying the component manager of all components implemented in
  89.      * this module.  The fileSpec, location and type parameters are mostly
  90.      * opaque, and should be passed on to the registerComponent call
  91.      * unmolested.
  92.      */
  93.     registerSelf: function (compMgr, fileSpec, location, type) {
  94.  
  95.         if (this.firstTime) {
  96.             this.firstTime = false;
  97.             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  98.         }
  99.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  100.         compMgr.registerFactoryLocation(NS_FDLPROC_CID,
  101.                                         "FDLProc",
  102.                                         NS_FDLPROC_PROG_ID, 
  103.                                         fileSpec,
  104.                                         location,
  105.                                         type);
  106.     },
  107.  
  108.     unregisterSelf: function(compMgr, fileSpec, location) {
  109.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  110.         compMgr.unregisterFactoryLocation(NS_DH_FDLPROC_CID, fileSpec);
  111.     },
  112.  
  113.     /*
  114.      * The GetClassObject method is responsible for producing Factory and
  115.      * SingletonFactory objects (the latter are specialized for services).
  116.      */
  117.     getClassObject: function (compMgr, cid, iid) {
  118.         if (!cid.equals(NS_FDLPROC_CID)) {
  119.             throw Components.results.NS_ERROR_NO_INTERFACE;
  120.         }
  121.  
  122.         if (!iid.equals(Components.interfaces.nsIFactory)) {
  123.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  124.         }
  125.  
  126.         return this.vFDLProcFactory;
  127.     },
  128.  
  129.     /* factory object */
  130.     vFDLProcFactory: {
  131.         /*
  132.          * Construct an instance of the interface specified by iid, possibly
  133.          * aggregating it with the provided outer.  (If you don't know what
  134.          * aggregation is all about, you don't need to.  It reduces even the
  135.          * mightiest of XPCOM warriors to snivelling cowards.)
  136.          */
  137.         createInstance: function (outer, iid) {
  138.             if (outer != null) {
  139.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  140.             }
  141.     
  142.             if(Util==null) {
  143.                 Util=Components.classes["@downloadhelper.net/util-service;1"]
  144.                     .getService(Components.interfaces.dhIUtilService);
  145.                 try {
  146.                     var jsLoader=Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
  147.                         .getService(Components.interfaces.mozIJSSubScriptLoader);
  148.                     jsLoader.loadSubScript("chrome://dwhelper/content/dlproc-helper.js");
  149.                 } catch(e) {
  150.                     dump("!!! [dhDownloadProcessor] createInstance: "+e+"\n");
  151.                 }
  152.             }
  153.  
  154.             return new FDLProc().QueryInterface(iid);
  155.         }
  156.     },
  157.  
  158.     /*
  159.      * The canUnload method signals that the component is about to be unloaded.
  160.      * C++ components can return false to indicate that they don't wish to be
  161.      * unloaded, but the return value from JS components' canUnload is ignored:
  162.      * mark-and-sweep will keep everything around until it's no longer in use,
  163.      * making unconditional ``unload'' safe.
  164.      *
  165.      * You still need to provide a (likely useless) canUnload method, though:
  166.      * it's part of the nsIModule interface contract, and the JS loader _will_
  167.      * call it.
  168.      */
  169.     canUnload: function(compMgr) {
  170.         return true;
  171.     }
  172. };
  173.  
  174. function NSGetModule(compMgr, fileSpec) {
  175.     return vFDLProcModule;
  176. }
  177.  
  178.